package com.fatmeraid.controller.login;


import com.fatmeraid.common.login.LoginUser;
import com.fatmeraid.common.login.LoginUserHolder;
import com.fatmeraid.common.result.Result;
import com.fatmeraid.common.utils.JwtUtil;
import com.fatmeraid.vo.Captcha;
import com.fatmeraid.vo.LoginVo;
import com.fatmeraid.domain.User;
import com.fatmeraid.service.LoginService;
import io.jsonwebtoken.Claims;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Tag(name = "登录")
@RestController
@RequestMapping("/login")
public class LoginController {

	@Autowired
	private LoginService loginService;

	@Operation(summary = "获取图像验证码")
	@GetMapping("/captcha")
	public Result<Captcha> getCaptcha(){
		Captcha captcha = loginService.getCaptcha();
		return Result.ok(captcha);
	}

	@Operation(summary = "用户登录")
	@PostMapping
	public Result<String> login(@RequestBody LoginVo loginVo){
		String jwt = loginService.login(loginVo);
		return Result.ok(jwt);
	}


	@Operation(summary = "获取登录用户个人信息")
	@GetMapping("/info")
	public Result<User> getInfo(){
		LoginUser loginUser = LoginUserHolder.getLoginUser();
		User user = loginService.getLoginUserInfoById(loginUser.getUserId());
		return Result.ok(user);
	}


}
